package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.bo.AdListBO;
import com.cskaoyan.bean.pojo.MarketTopic;
import com.cskaoyan.bean.vo.TopicListVO;
import com.cskaoyan.bean.vo.TopicReadVO;
import com.cskaoyan.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 专题管理模块
 *
 * @author chenxu
 * @since 2022/04/07 17:10
 */
@RestController
@RequestMapping("admin")
public class TopicController {

    @Autowired
    TopicService topicService;

    //查看/查找页面专题信息
    @RequestMapping("topic/list")
    public BaseRespVo list(AdListBO adListBO){

        TopicListVO topicListVO = topicService.list(adListBO);
        return BaseRespVo.ok(topicListVO);
    }

    //删除专题信息
    @PostMapping("topic/delete")
    public BaseRespVo delete(@RequestBody MarketTopic marketTopic){

        topicService.delete(marketTopic);
        return BaseRespVo.ok();
    }

    //批量删除
    @PostMapping("topic/batch-delete")
    public BaseRespVo BatchDelet(@RequestBody AdListBO adListBO ){
        topicService.batchDelet(adListBO.getIds());
        return BaseRespVo.ok();
    }
    //添加专项管理信息
    @PostMapping("topic/create")
    public BaseRespVo create( @RequestBody MarketTopic marketTopic){
       MarketTopic marketTopic1 = topicService.create(marketTopic);
       return  BaseRespVo.ok(marketTopic1);
    }
    //修改专项
    @PostMapping("topic/update")
    public BaseRespVo update(@RequestBody MarketTopic marketTopic){
       MarketTopic marketTopic1 = topicService.update(marketTopic);
       return BaseRespVo.ok(marketTopic1);
    }

    //读取编辑的信息
    @GetMapping ("topic/read")
    public BaseRespVo read(Integer id){
       TopicReadVO topicReadVO = topicService.read(id);
       return BaseRespVo.ok(topicReadVO);
    }
}
